package com.newcapce.chat;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws IOException {
        //客户端窑连接服务器
        Socket socket = new Socket("192.168.0.127",1111);

        DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());

        new Thread(){
            @Override
            public void run() {
                try {
                    while(true){
                        String revStr = dataInputStream.readUTF();
                        System.out.println("接收到:"+revStr);
                    }
                }catch (Exception e){
                    System.out.println("客户端异常断开");
                }
            }
        }.start();

        Scanner scanner = new Scanner(System.in);
        while(true){
            String sendStr = scanner.nextLine();
            dataOutputStream.writeUTF(sendStr);
            dataOutputStream.flush();
        }
    }
}
